layui.use('table', function () {
    var table = layui.table;

    table.render({
        elem: '#table',
        url: '/back/product/findAll',
        cols: [[ //表头
            {field: 'id', title: 'ID', width: 80, fixed: 'left', totalRowText: '合计：'}
            , {field: 'name', title: '产品名称', width: 80}
            , {
                field: 'imgHref', title: '产品图片', width: 90, templet: function (data) {
                    return "<img src='" + data.imgHref + "' width='50' height='30'>";
                }
            }
            , {field: 'cuisineName', title: '菜系名称'}
            , {field: 'marketPrice', title: '市场价', width: 80}
            , {field: 'normalPrice', title: '正常价', width: 80}
            , {fixed: 'right', width: 150, align: 'center', toolbar: '#barDemo'}
        ]],
        page: true
    });


    //监听行工具事件
    table.on('tool(table)', function (obj) {
        var data = obj.data;
        //console.log(obj)
        if (obj.event === 'del') {
            layer.confirm('真的删除行么', function (index) {
                obj.del();
                layer.close(index);
            });
        } else if (obj.event === 'edit') {
            sessionStorage.setItem("productId", data.id);
            xadmin.open('编辑产品', '/html/product/product-edit.html', 600, 400);
        }
    });
});